<template>
  <section class="index ">
    <scroll class="wrapper" @scroll="scroll($event)">
      <!--Head-->

      <Head @handleStatus='handleTab'></Head>
      <!--Head-->
      <div v-if="status == 1">
        <!-- 轮播 -->
        <div class="clearfix banner-box boutique-tuan-section">
          <div class="banner fl" id="banner">
            <ul class="clearfix banner-list" style="left: 0px;">
              <el-carousel trigger="click" :interval='5000' :autoplay='true' :loop='true'>
                <el-carousel-item v-for="(item, index) in shopList.carousel" :key="index">
                  <img :src="imgUrl.img+item.carousel_path" width="900px" height="500px">
                </el-carousel-item>
              </el-carousel>
            </ul>
          </div>
          <!--广告-->
          <ul class="fl ad-list">
            <li v-if="index<3" v-for="(item, index) in shopList.activityFour" :key="index" @click="handleDetail(item.activity_url)">
              <a>
                <div class="flex allHeight flex-v">
                  <div class="flex-1">
                    <img :src="imgUrl.img + item.activity_img" width="300px" height="140px" style="object-fit: fill;">
                  </div>
                  <div class=" flex flex-2">
                    <div>{{item.activity_title}}</div>
                    <div class="price">￥{{item.activity_volume}}</div>
                  </div>

                </div>
              </a>
            </li>

          </ul>
        </div>
        <!-- 轮播 -->
        <!-- 今日活动 -->
        <div class="boutique-tuan-section">
          <div class="clearfix boutique-tuan-section">
            <h3 class="fl tit1">今日活动</h3>
          </div>
          <div class="boutique-tuan-list">
            <div class="bx-wrapper" style="max-width: 1200px; margin: 0px auto;">
              <div class="bx-viewport" style="width: 100%; overflow: hidden; position: relative; height: 363px;">
                <ul class="list-slider clearfix" id="list-slider" style="width: 615%; position: relative; transition-duration: 0s; transform: translate3d(0px, 0px, 0px);">
                  <li style="float: left; list-style: none; position: relative; width: 269px;" class="bx-clone" v-for="(item, index) in shopList.activityOne"
                    :key="index" @click="$router.push({path: 'Details', query: {id: item.activity_url}})">
                    <div class="pic">
                      <a>
                        <img width="201" height="201" :src="imgUrl.img + item.activity_img">
                      </a>
                    </div>
                    <div class="title">
                      <a>
                        {{item.activity_title}}
                      </a>
                    </div>
                    <div class="price">{{item.activity_volume}}
                    </div>
                    <div class="shop-name">
                      <a> {{item.activity_introduction}}</a>
                    </div>
                    <a class="btn">立即抢购</a>
                  </li>
                </ul>
              </div>
            </div>
          </div>
        </div>
        <!-- 今日活动 -->
        <!-- 今日推荐 -->
        <div class="boutique-tuan-section">
          <div class="clearfix">
            <h3 class="fl tit1">今日推荐</h3>
          </div>
          <ul class="commodity-list clearfix">
            <li class="commodity-item" v-for="(item, index) in list" :key="index">
              <div class="commodity-item-link" @click="$router.push({path: '/Details',query: {id: item.goods_id}})">
                <div class="item-pic">
                  <div class="pic-img">
                    <img class="lazy" :src="imgUrl.img + item.goods_pic" style="display: block;">
                  </div>
                </div>
                <div class="item-info">
                  <div class="item-desc">
                    <p class="item-name">{{item.goods_short_title}}</p>
                    <span class="item-intro">国行原封，顺丰包邮，发货后不支持7天无理由退货</span>
                  </div>
                  <div class="item-detail clearfix">
                    <div class="item-detail-left">
                      <div class="item-price">
                        <span class="xj-price">
                          <em>￥</em>
                          <span>{{item.goods_present_price}}</span>
                        </span>
                      </div>
                    </div>
                    <div class="item-btn">
                      <span class="item-btn-con">立即购买</span>
                    </div>
                  </div>
                </div>
              </div>
            </li>
          </ul>
        </div>
        <div @click="searchMore" v-if="isShowMore" class="more">加载更多<i class="icon inonfont icon-more"></i> </div>
        <!-- 今日推荐 -->
      </div>
      <!--京东-->
      <div  class="comm" v-if="status == 2">
      正在完善中
      </div>
      <!--京东-->
      <!--严选-->
      <div  class="comm" v-if="status == 3">
      正在完善中
      </div>
      <!--严选-->
    </scroll>
    <!-- 底部 -->
    <BackTop v-if="backTop"></BackTop>
    <Footer></Footer>
    <!-- 底部 -->
  </section>
</template>
<script>
  import * as API from '@/api/index';
  import BackTop from '@/components/backtop';
  import Scroll from '@/components/scroll'
  import Footer from '@/components/footer'
  import Head from './header.vue'
  export default {
    name: 'index',
    data() {
      return {
        shopList: [],
        list: [],
        page: 1,
        page_number: 10,
        count: 0,
        status: 1,
        backTop: false, //是否显示返回顶部按钮
        isShowMore: true //是否显示“加载更多数据”
      }
    },
    components: {
      Footer,
      Scroll,
      BackTop,
      Head
    },
    created() {
      this.getData();
      this.gg();
    },
    methods: {
      handleTab(num) {
        this.status = num;
      },
      handleDetail(name) {
        const data = {
          '床': '813',
          '蜂蜜': '823',
          '白酒': '917'
        }
        this.$router.push({
          path: 'Details',
          query: {
            id: data[name]
          }
        })
      },
      scroll(e) {
        e > 500 ? this.backTop = true : this.backTop = false
      },
      searchMore() {
        this.page++
        if (this.page * this.page_number >= this.count) {
          this.count = false;
        } else {
          this.gg();
        }

      },
      async getData() {
        const data = {
          service: 'Pro.Cache.IndexCache'
        }
        const res = await API.toIndex(data)
        if (res.ret == 200) {
          this.shopList = res.data;
        }
      },
      async gg() {
        const data = {
          service: 'Pro.Goods.GoodsList',
          goods_type: 1,
          page: this.page,
          page_number: this.page_number,
          order: 1,
          goods_is_q: 1,
        }
        const res = await API.toIndex(data)
        if (res.ret == 200) {
          this.count = res.data.count;
          this.list = [...this.list, ...res.data.lists];
        }
      },
    }
  }

</script>
<style lang='css'>
  @import '../../scss/home.css';
  @import '../../scss/details.css';
.index .wrapper {
  margin: 0 auto;
  width: 1208px!important;
}
  .banner-box {
    display: flex;
  }

  .flex {
    display: flex;
    color: #202020;
    width: 279px;
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: left;
    padding: 0 15px;
  }

  .flex-2 {
    width: 100%;
    padding: 0;
    justify-content: space-between;

  }

  .flex-1 {
    width: 100%;
  }

  .flex-v {
    flex-direction: column;
  }

  .es {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .price {
    color: #c00;
    font-size: 16px;
  }

  .buy {
    width: 80px;
    height: 30px;
    background: #c00;
    color: #fff;
    border-radius: 4px;
    line-height: 30px;
    text-align: center;
    transform: translate3d(0, -2px, 0);
  }

  .allHeight {
    height: 170px;
  }

  .icon-more {
    width: 30px;
    height: 30px;
    background: url(../image/more.png) no-repeat 100%;
    background-size: 80%;
  }

  .more {
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 18px;
    padding: 15px 0;
    width: 50%;
    margin: 10px auto;
    border: 1px #f3f4f5 solid;
    cursor: pointer;
    box-shadow: 1px 1px 10px #f3f4f5;
  }
 .comm{
    height: calc(100vh - 281px);
    display: flex;
    align-items: center;
    justify-content: center;
font-size: 18px;
  }

</style>
